﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace WebJobAsTimerService
{
    public class TemplateManager
    {
        public static string GetEmailBody(string templateName, object modelData)
        {
            var currentFolder = GetCurrentExecutingDirectory(Assembly.GetExecutingAssembly());
            var template = File.ReadAllText(string.Format("{0}/EmailTemplates/{1}", currentFolder, templateName));

            var messageBody = RazorEngine.Razor.Parse(template, modelData);

            return messageBody;
        }
        private static string GetCurrentExecutingDirectory(Assembly assembly)
        {
            string filePath = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
            return Path.GetDirectoryName(filePath);
        }
    }
}
